//
//  ZBOneViewC.m
//  BaseRACDemo
//
//  Created by 庄波 on 2018/3/7.
//  Copyright © 2018年 庄波. All rights reserved.
//

#import "ZBOneViewC.h"
#import "ZBOneItemViewModel.h"
@interface ZBOneViewC ()
@property (nonatomic, readwrite, strong) ZBOneModel *viewModel;

@end

@implementation ZBOneViewC

- (void)viewDidLoad {
    /// ①：子类调用父类的viewDidLoad方法，而父类主要是创建tableView以及强行布局子控件，从而导致tableView刷新，这样就会去走tableView的数据源方法
    [super viewDidLoad];
    /// 设置
    [self _setup];
    /// ③：注册cell
    [self.tableView mh_registerCell:UITableViewCell.class];
    
}

#pragma mark - Override
/// 配置tableView的区域
- (UIEdgeInsets)contentInset{
    return UIEdgeInsetsMake(SafeAreaTopHeight, 0, SafeAreaTabbarHeight, 0);
}

/// 返回自定义的cell
- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
    // ②：父类的tableView的数据源方法的获取cell是通过注册cell的identifier来获取cell，然而此时子类并未注册cell，所以取出来的cell = nil而引发Crash
    return [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    // 非注册cell 使用时：去掉ViewDidLoad里面注册Cell的代码
    //    return [MHMainFrameTableViewCell cellWithTableView:tableView];
}

/// 绑定数据
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{
//    [cell bindViewModel:object];
    ZBOneNoteNoticeList *model = ((ZBOneItemViewModel*)object).noticeList;
    cell.textLabel.text = model.title;
}

#pragma mark - 初始化
- (void)_setup{
    /// set up ...
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self.viewModel.dataSource[indexPath.row] cellHeight] ;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
